package com.mzlalal.donate.controller;

import com.mzlalal.donate.model.robot.RobotRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @description: 智能客服controller
 * @author: Mzlalal
 * @date: 2020/1/1 23:30
 * @version: 1.0
 */
@Slf4j
@RestController
public class RobotController {

    @Autowired
    RestTemplate restTemplate;

    private String apiKey = "dd133b19dd854f229eccafcf24f590b";

    @RequestMapping("/robotReplyText")
    public String robotReplyText(String inputText) {
        // 图灵机器人接口访问地址
        String robotUrl = "http://openapi.tuling123.com/openapi/api/v2";
        RobotRequest request = new RobotRequest();
        // 输入类型:0-文本(默认)、1-图片、2-音频
        request.setReqType(0);
        // 设置文本
        request.getPerception().getInputText().setText(inputText);
        // 设置开发者接口授权钥匙
        request.getUserInfo().setApiKey(apiKey);
        request.getUserInfo().setUserId("1");
        // 开始请求
        String response = restTemplate.postForObject(robotUrl, request, String.class);
        return response;
    }
}
